﻿using ICMS.PluginInterfaces;
using commonImportPlugin.FilesCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using commonImportPlugin.Config;
using commonImportPlugin.Configs.Other;
using commonImportPlugin.Core.Match;

namespace commonImportPlugin.Factorys
{
    //
    //  抽象工厂
    //
    #region
    /// <summary>
    /// 匹配工厂类
    /// </summary>
    public abstract class AbstractFactoryMatch
    {
        public abstract MatchCore CreateMatch();
    }
    public abstract class MatchCore
    {
        /// <summary>
        /// 通用匹配函数接口
        /// </summary>
        /// <typeparam name="T1">可变参数类型1</typeparam>
        /// <typeparam name="T2">可变参数类型2</typeparam>
        /// <typeparam name="C">可变参数类型3</typeparam>
        /// <param name="Data1">数据集1</param>
        /// <param name="Data2">数据集2</param>
        /// <param name="orderId">工单号</param>
        /// <param name="errorIsContinue">错误是否继续</param>
        /// <param name="paramList">可变参数</param>
        /// <returns>最总的ICData</returns>
        public abstract List<ICData> CommonMatch<T1, T2>(T1 Data1, T2 Data2,string orderId,params object[] paramList);    
        /// <summary>
        /// 一种格式间的匹配
        /// </summary>
        /// <typeparam name="T">可变参类型1</typeparam>
        /// <typeparam name="C">可变参配置</typeparam>
        /// <param name="match1">匹配的数据1</param>
        /// <param name="match2">匹配的数据2</param>
        /// <param name="_config">配置参数</param>
        /// <param name="orderId">工单号</param>
        /// <param name="errorIsContinue">错误是否继续</param>
        /// <param name="paramList">扩展参数</param>
        /// <returns>匹配结果,null表示失败</returns>
        protected abstract List<T> OneFormatMatch<T,C>(List<T> match1, List<T> match2,C _config,string orderId,params object[] paramList);
        /// <summary>
        /// 两种格式间的匹配
        /// </summary>
        /// <typeparam name="T1">可变参类型1</typeparam>
        /// <typeparam name="T2">可变参类型2</typeparam>
        /// <typeparam name="C">可变参配置</typeparam>
        /// <param name="match1">匹配的数据1</param>
        /// <param name="match2">匹配的数据2</param>
        /// <param name="_config">配置参数2</param>
        /// <param name="orderId">工单号</param>
        /// <param name="errorIsContinue">错误是否继续</param>
        /// <param name="paramList">扩展参数</param>
        /// <returns>匹配结果,null表示失败</returns>
        protected abstract List<T1> TwoFormatMatch<T1, T2,C>(List<T1> match1, List<T2> match2, C _config,string orderId,params object[] paramList); 
    }
    #endregion

    //
    //  工厂集
    //
    #region
    //通用模式1
    public class MatchCoreGeneralFactory : AbstractFactoryMatch
    {
        public override MatchCore CreateMatch()
        {
            matchCoreGeneral core = new matchCoreGeneral();
            return core.GetInstance();
        }
    }
    #endregion

    //
    //  简单工厂
    //
    #region
    /// <summary>
    /// 匹配简单工厂
    /// </summary>
    public class setMatchFactory
    {
        public MatchCore createFactory(string whichFactory)
        {
            switch (whichFactory)
            {
                case "General":
                    //初始化配置
                    MatchConfig matchConfig = new MatchConfig();
                    matchConfig.Init();
                    //返回初始化核心
                    return new MatchCoreGeneralFactory().CreateMatch();     
                default:
                    break;
            }
            throw new Exception("工厂配置" + whichFactory + "不存在，请检查！");
        }
    }
    #endregion
}
